package utility;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class RandomQry
 */
public class RandomQry extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RandomQry() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	public static void main(String[] args) throws Exception {
		int[] sc = {23,24,26,25,1,2,3,21,4,27,5,6,7,12};
		String[] ct = {"MA","MA","MA","MA","MA","MA","MB","MB","SA","SA","SA","SA","SA","SA"};
		String[] fn = {"99999999999","88888888888","77777777777"};
		String seriale;
		String sottocategoria;
		String fornitore;
		int rnd;
		
		FileOutputStream file = new FileOutputStream("c:\\qry.txt");
	    PrintStream out = new PrintStream(file);

		
		for (int i=2;i<500;i++)
		{
			rnd =(int) (Math.random()*14);
			sottocategoria = Integer.toString(sc[rnd]);
			seriale = ct[rnd];
			fornitore = fn[(int)(Math.random()*3)];
			
			String qry = "INSERT INTO BENE VALUES (" + i +
			             ",'" + i + "/" + seriale + "'," +
			             pickprice() + "," + pickdate() +
			             "," + pickbit() + "," + pickdate() + "," + pickdate() +
			             "," + pickbit() + "," + pickbit() + ",'" + sottocategoria + "','" +
			             fornitore + "'," + pickbit() + ",'CREATO A CASO!!!');";
			out.println(qry);
		}
		out.close();
		file.close();
	}
	
	private static String pickprice()
	{
		int price = (int) (Math.random()*5000)+50;
		return "" + price;
	}
	
	private static String pickdate()
	{
		int day = (int) (Math.random()*28)+1;
		int month = (int) (Math.random()*12)+1;
		int year = (int) (Math.random()*10)+2000;
		
		return "TO_DATE('" + day + "/" + month + "/" + year + "','DD/MM/YYYY')";	
	}
	
	private static String pickbit()
	{
		int bit = (int) (Math.random()*2)+1;
		return "'" + (bit-1) + "'";
	}

}
